Skip to content

Conversation

@MarcelStommel
Copy link
Contributor

@MarcelStommel MarcelStommel commented Jan 20, 2026

Description of Change

Changes the request handler for the now playing artwork to only capture the actual url string. This breaks a reference cycle with MPNowPlayingInfo and MPMediaItemArtwork where MPMediaItemArtwork keeps itself alive through the request handler delegate capturing the whole media element which holds their handler, holding the Metadata class, holding MPNowPlayingInfo, which finally holds MPMediaItemArtwork again. I did not add a test, since the changes are minimal, just changing how the artwork url is captured to avid the reference cycle.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

Copilot AI review requested due to automatic review settings January 20, 2026 13:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a memory leak in the MediaElement component on iOS/macOS by refactoring how the now playing artwork request handler is managed. The memory leak occurred due to a reference cycle where MPMediaItemArtwork captured the mediaElement instance through its request handler delegate, while the Metadata class holding the MPMediaItemArtwork was itself referenced by the media element.

Changes:

  • Introduced a new RequestHandlerProxy class that captures only the artwork URL string instead of the entire media element object
  • Added CoreGraphics using directive for the CGSize type
  • Refactored the artwork request handler to use the proxy class method reference instead of a lambda

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 20, 2026 13:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copy link
Member

@ne0rrmatrix ne0rrmatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty for the PR. Good catch. I have tested this in the simulator and I see no issues with this.

@TheCodeTraveler TheCodeTraveler merged commit e87950e into CommunityToolkit:main Jan 20, 2026
10 checks passed
@MarcelStommel MarcelStommel deleted the fix/media-element-disconnect branch January 21, 2026 09:16
@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Media Element cannot be disconnected

4 participants